package com.bonc.excel.configuration;


import com.alibaba.ttl.TransmittableThreadLocal;
import com.bonc.excel.dto.response.ExcelResponse;
import lombok.extern.slf4j.Slf4j;

/**
 *
 */
@Slf4j
public class DataContextHolder {
    private static final InheritableThreadLocal<ExcelResponse> channel = new TransmittableThreadLocal<ExcelResponse>();

    /**
     * 清除当前数据源
     */
    public static void clear(){
        channel.remove();
    }

    /**
     * 获取当前使用的数据源
     * @return
     */
    public static ExcelResponse get(){
        if(channel.get() == null){
            channel.set(new ExcelResponse());
        }
        return channel.get();

    }

    /**
     * 设置当前使用的数据源
     * @param data
     */
    public static void set(ExcelResponse data){
        channel.set(data);
    }
}